<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta name="Content-Type" content="text/html; charset=UTF-8" />
<title>Class: Sass::Util::SubsetMap</title>
<link rel="stylesheet" href="style.css" tppabs="http://sass-lang.com/docs/yardoc/css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="common.css" tppabs="http://sass-lang.com/docs/yardoc/css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '../..';
  if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="jquery.js" tppabs="http://sass-lang.com/docs/yardoc/js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="app.js" tppabs="http://sass-lang.com/docs/yardoc/js/app.js"></script>

  </head>
  <body>
    <script type="text/javascript" charset="utf-8">
      if (window.top.frames.main) document.body.className = 'frames';
    </script>
    
    <div id="header">
      <div id="menu">
  
    <a href="_index.html" tppabs="http://sass-lang.com/docs/yardoc/_index.html">Index (S)</a> &raquo; 
    <span class='title'><a href="Sass-1.html" tppabs="http://sass-lang.com/docs/yardoc/Sass.html" title="Sass (module)">Sass</a></span> &raquo; <span class='title'><a href="Util.html" tppabs="http://sass-lang.com/docs/yardoc/Sass/Util.html" title="Sass::Util (module)">Util</a></span>
     &raquo; 
    <span class="title">SubsetMap</span>
  
  
  <div class="noframes"><span class="title">(</span><a href="javascript:if(confirm(%27http://sass-lang.com/docs/yardoc/Sass/Util/.  \n\nThis file was not retrieved by Teleport Pro, because the server reports that this file cannot be found.  \n\nDo you want to open it from the server?%27))window.location=%27http://sass-lang.com/docs/yardoc/Sass/Util/.%27" tppabs="http://sass-lang.com/docs/yardoc/Sass/Util/." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  <a id="class_list_link" href="#">Class List</a>
  <a id="method_list_link" href="#">Method List</a>
  <a id ="file_list_link" href="#">File List</a>
</div>

      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><h1>Class: Sass::Util::SubsetMap 
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">Object</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">Sass::Util::SubsetMap</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">/var/www/sass-pages/.sass/lib/sass/util/subset_map.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <p>A map from sets to values. A value is <tt><a href="#%5B%5D%3D-instance_method" title="Sass::Util::SubsetMap#[]= (method)">set</a></tt> by providing a set (the &#8220;set-set&#8221;) and a value, which is then recorded as corresponding to that set. Values are <tt><a href="#%5B%5D-instance_method" title="Sass::Util::SubsetMap#[] (method)">accessed</a></tt> by providing a set (the &#8220;get-set&#8221;) and returning all values that correspond to set-sets that are subsets of the get-set.</p>

<p>SubsetMap preserves the order of values as they&#8217;re inserted.</p>

  </div>
</div>
<div class="tags">
  
  <div class="examples">
    <h3>Examples:</h3>
    
      <h4></h4>
      <pre class="example code">  ssm = SubsetMap.new
  ssm[Set[1, 2]] = "Foo"
  ssm[Set[2, 3]] = "Bar"
  ssm[Set[1, 2, 3]] = "Baz"

  ssm[Set[1, 2, 3]] #=> ["Foo", "Bar", "Baz"]</pre>
    
  </div>

</div>


  <h2>Instance Method Summary</h2>

  <ul class="summary">
    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#%5B%5D-instance_method" title="#[] (instance method)">- (Array) <strong>[]</strong>(set) </a>
    

    
  </span>
  
  
  
  
  

  
    <span class="summary_desc">Same as <tt><a href="#get-instance_method" title="Sass::Util::SubsetMap#get (method)">#get</a></tt>, but doesn&#8217;t return the subsets of the argument for which values were found.</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#%5B%5D%3D-instance_method" title="#[]= (instance method)">- <strong>[]</strong>(set, value) </a>
    

    
  </span>
  
  
  
  
  

  
    <span class="summary_desc">Associates a value with a set.</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#each_value-instance_method" title="#each_value (instance method)">- <strong>each_value</strong> {|Object| ... }</a>
    

    
  </span>
  
  
  
  
  

  
    <span class="summary_desc">Iterates over each value in the subset map.</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#empty%3F-instance_method" title="#empty? (instance method)">- (Boolean) <strong>empty?</strong> </a>
    

    
  </span>
  
  
  
  
  

  
    <span class="summary_desc">Whether or not this SubsetMap has any key-value pairs.</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#get-instance_method" title="#get (instance method)">- (Array&lt;(Object, #to_set)&gt;) <strong>get</strong>(set) </a>
    

    
  </span>
  
  
  
  
  

  
    <span class="summary_desc">Returns all values associated with subsets of <code>set</code>.</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature">
    
      <a href="#initialize-instance_method" title="#initialize (instance method)">- (SubsetMap) <strong>initialize</strong> </a>
    

    
  </span>
  
    <span class="note title constructor">constructor</span>
  
  
  
  
  

  
    <span class="summary_desc">Creates a new, empty SubsetMap.</span>
  
</li>

    
  </ul>
<div id="constructor_details" class="method_details_list">
  <h2>Constructor Details</h2>
  
    <div class="method_details first">
  <p class="signature first" id="initialize-instance_method">
  
    - (<tt><a href="" title="Sass::Util::SubsetMap (class)">SubsetMap</a></tt>) <strong>initialize</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>Creates a new, empty SubsetMap.</p>

  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


23
24
25
26</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/util/subset_map.rb', line 23</span>

def initialize
  @hash = {}
  @vals = []
end</pre>
    </td>
  </tr>
</table>
</div>
  
</div>


  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>
    
    
      <div class="method_details first">
  <p class="signature first" id="[]-instance_method">
  
    - (<tt>Array</tt>) <strong>[]</strong>(set) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>Same as <tt><a href="#get-instance_method" title="Sass::Util::SubsetMap#get (method)">#get</a></tt>, but doesn&#8217;t return the subsets of the argument for which values were found.</p>

  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='type'>(<tt>Set</tt>)</span>
      
      
        <span class='name'>set</span>
      
      
      
        &mdash;
        The set to use as the map key.
      
    </li>
  
</ul>
<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
        <span class='type'>(<tt>Array</tt>)</span>
      
      
      
      
        &mdash;
        The array of all values associated with subsets of <code>set</code>, in insertion order.
      
    </li>
  
</ul>

  <h3>See Also:</h3>
  <ul class="see">
    
      <li><a href="#get-instance_method" title="Sass::Util::SubsetMap#get (method)">#get</a></li>
    
  </ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


96
97
98</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/util/subset_map.rb', line 96</span>

def [](set)
  get(set).map {|v, _| v}
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="[]=-instance_method">
  
    - <strong>[]=</strong>(set, value) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>Associates a value with a set. When <code>set</code> or any of its supersets is accessed, <code>value</code> will be among the values returned.</p>

<p>Note that if the same <code>set</code> is passed to this method multiple times, all given <code>value</code>s will be associated with that <code>set</code>.</p>

<p>This runs in <code>O(n)</code> time, where <code>n</code> is the size of <code>set</code>.</p>

  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='type'>(<tt>#to_set</tt>)</span>
      
      
        <span class='name'>set</span>
      
      
      
        &mdash;
        The set to use as the map key. May not be empty.
      
    </li>
  
    <li>
      
        <span class='type'>(<tt>Object</tt>)</span>
      
      
        <span class='name'>value</span>
      
      
      
        &mdash;
        The value to associate with <code>set</code>.
      
    </li>
  
</ul>
<h3>Raises:</h3>
<ul class="raise">
  
    <li>
      
        <span class='type'>(<tt>ArgumentError</tt>)</span>
      
      
      
      
        &mdash;
        If <code>set</code> is empty.
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


47
48
49
50
51
52
53
54
55
56</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/util/subset_map.rb', line 47</span>

def []=(set, value)
  raise ArgumentError.new("SubsetMap keys may not be empty.") if set.empty?

  index = @vals.size
  @vals << value
  set.each do |k|
    @hash[k] ||= []
    @hash[k] << [set, set.to_set, index]
  end
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="each_value-instance_method">
  
    - <strong>each_value</strong> {|Object| ... }
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>Iterates over each value in the subset map. Ignores keys completely. If multiple keys have the same value, this will return them multiple times.</p>

  </div>
</div>
<div class="tags">
  <h3>Yields:</h3>
<ul class="yield">
  
    <li>
      
        <span class='type'>(<tt>Object</tt>)</span>
      
      
      
      
        &mdash;
        Each value in the map.
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


104
105
106</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/util/subset_map.rb', line 104</span>

def each_value
  @vals.each {|v| yield v}
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="empty?-instance_method">
  
    - (<tt>Boolean</tt>) <strong>empty?</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>Whether or not this SubsetMap has any key-value pairs.</p>

  </div>
</div>
<div class="tags">
  <h3>Returns:</h3>
<ul class="return">
  
    <li>
      
        <span class='type'>(<tt>Boolean</tt>)</span>
      
      
      
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


31
32
33</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/util/subset_map.rb', line 31</span>

def empty?
  @hash.empty?
end</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="get-instance_method">
  
    - (<tt>Array&lt;(Object, #to_set)&gt;</tt>) <strong>get</strong>(set) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>Returns all values associated with subsets of <code>set</code>.</p>

<p>In the worst case, this runs in <code>O(m*max(n, log m))</code> time, where <code>n</code> is the size of <code>set</code> and <code>m</code> is the number of assocations in the map. However, unless many keys in the map overlap with <code>set</code>, <code>m</code> will typically be much smaller.</p>

  </div>
</div>
<div class="tags">
  <h3>Parameters:</h3>
<ul class="param">
  
    <li>
      
        <span class='type'>(<tt>Set</tt>)</span>
      
      
        <span class='name'>set</span>
      
      
      
        &mdash;
        The set to use as the map key.
      
    </li>
  
</ul>
<h3>Returns:</h3>
<ul class="return">
  
    <li>
      
        <span class='type'>(<tt>Array&lt;(Object, #to_set)&gt;</tt>)</span>
      
      
      
      
        &mdash;
        An array of pairs, where the first value is the value associated with a subset of <code>set</code>, and the second value is that subset of <code>set</code> (or whatever <code>#to_set</code> object was used to set the value) This array is in insertion order.
      
    </li>
  
</ul>

  <h3>See Also:</h3>
  <ul class="see">
    
      <li><a href="#%5B%5D-instance_method" title="Sass::Util::SubsetMap#[] (method)">#[]</a></li>
    
  </ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File '/var/www/sass-pages/.sass/lib/sass/util/subset_map.rb', line 73</span>

def get(set)
  res = set.map do |k|
    next unless subsets = @hash[k]
    subsets.map do |subenum, subset, index|
      next unless subset.subset?(set)
      [index, subenum]
    end
  end
  res = Sass::Util.flatten(res, 1)
  res.compact!
  res.uniq!
  res.sort!
  res.map! {|i, s| [@vals[i], s]}
  return res
end</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>
    
    <div id="footer">
  Generated on Fri Mar  8 20:33:48 2013 by 
  <a href="javascript:if(confirm(%27http://yardoc.org/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?%27))window.location=%27http://yardoc.org/%27" tppabs="http://yardoc.org/" title="Yay! A Ruby Documentation Tool">yard</a>
  0.5.3 (ruby-1.8.7).
</div>


  <script type="text/javascript">
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  </script>
  <script type="text/javascript">
  try {
  var pageTracker = _gat._getTracker("UA-535380-8");
  pageTracker._trackPageview();
  } catch(err) {}</script>


  </body>
</html>